<?php


namespace App\Utils\Notice;

use App\Constants\Model\Notice as NoticeConstants;
use App\Model\NoticeEmployer;
use Hyperf\DbConnection\Model\Model;

/**
 * 仲裁结果通知（合作商->悬赏主）
 * Class EmployerArbitrateEnd
 * @package App\Utils\Notice
 */
class EmployerArbitrateEnd extends Notice
{
    public $template = '您好，运营人员已对你们的任务争议做了仲裁。请您注意查看';

    public $model = NoticeEmployer::class;

    public $routeName = '/pages/rewardTask/arbitration?type=5';

    public $data;

    public function toDatabase()
    {
        $data = $this->format($this->data);
        /** @var Model $model */
        $model = new $this->model;
        $model->fill($data)->save();
    }


    public function format(array $data)
    {
        $return = [];
        //定义通知的类型
        $return['type'] = NoticeConstants::EMPLOYER_ARBITRATE_END;
        //扩展字段
        $return['extension'] = isset($data['extension']) ? $data['extension'] : [];
        //接受者id
        $return['employer_id'] = $this->receiverId;

        $return['extension']['path'] = $this->routeName;

        if (isset($data['replaces'])) {
            $return['content'] = sprintf($this->template,$data['replaces']);
        } else {
            $return['content'] = $this->template;
        }

        return $return;
    }


}